package top.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import top.api.common.ResUlt;
import top.api.domain.dto.PageDto;
import top.api.domain.pojo.UserInfo;
import top.api.domain.vo.PageVo;
import top.api.service.UserInfoService;
import top.api.mapper.UserInfoMapper;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 86191
* @description 针对表【user_info(用户信息表)】的数据库操作Service实现
* @createDate 2024-05-27 08:44:53
*/
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService{

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Override
    public ResUlt<?> listPage(PageDto pageDto, Integer id, String nickName) {
        IPage<UserInfo> page= new Page<>(pageDto.getPageNum(),pageDto.getPageSize());
        LambdaQueryWrapper<UserInfo> lwq = new LambdaQueryWrapper<>();
        lwq.like(Strings.isNotEmpty(nickName),UserInfo::getNickName,nickName);
        lwq.eq(ObjectUtils.isNotEmpty(id),UserInfo::getUserId,id);
        userInfoMapper.selectPage(page, lwq);
        PageVo<UserInfo> pageVo = new PageVo<>(page.getRecords(),page.getTotal());
        return ResUlt.success(pageVo);
    }
}




